package com.zy.qudadid.presenter;


import com.zy.qudadid.model.Res;
import com.zy.qudadid.model.Travel;
import com.zy.qudadid.network.Const;
import com.zy.qudadid.network.Net;
import com.zy.qudadid.presenter.base.BasePresenterImp;
import com.zy.qudadid.ui.view.IndexFormView;

import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by ninos on 2016/7/30.
 */
public class IndexFormPresenter extends BasePresenterImp<IndexFormView> {

//    /api.php?c=infoOrderCar&a=passengerOrderparticulars&args=
    public void passengerOrder(String data){
        Subscription subscription = Net.getService()
                .passengerOrder(data)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Res<Travel>>() {

                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
//                        view.error();
                    }

                    @Override
                    public void onNext(Res<Travel> res) {
                        if (res.code == Const.OK){
                            view.success(res.datas);
                        }else {
                            view.error();
                        }
                    }
                });

        addSubscription(subscription);
    }

    public void changeOrderstate(String data){
//        {$api_url}/api.php?c=infoOrderCar&a=changeOrderstate&args=
        Subscription subscription = Net.getService()
                .changeOrderstate("infoOrderCar","changeOrderstate",data)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Res>() {

                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        view.error();
                    }

                    @Override
                    public void onNext(Res res) {
                        if (res.code== Const.OK){
                            view.successstate();
                        }else {
                            view.errorstate();
                        }
                    }
                });

        addSubscription(subscription);
    }

    public void postcomment(String data){
//        c=info&a=postcomment_fordriver_afterpay&args=
        Subscription subscription = Net.getService()
                .postcomment("info","postComments",data)
//                .postcomment("info","postcomment_fordriver_afterpay",data)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Res>() {

                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        view.errorp();
                    }

                    @Override
                    public void onNext(Res res) {
                        if (res.code== Const.OK){
                            view.successp();
                        }else {
                            view.errorp();
                        }
                    }
                });
        addSubscription(subscription);
    }
}
